package com.demo.coupon;


import com.demo.AppletConstant;
import com.demo.util.Utils;

import java.util.HashMap;
import java.util.Map;


/**
 * 抽奖资格赠送
 *
 */
public class QualSend {
	public static void main(String[] args)  throws Exception{

		//调用接口地址
		String url = "https://open.95516.com/open/access/1.0/qual.send";
		
		//拼装参数Map
		Map<String, String> params = new HashMap<String, String>(0);
		params.put("appId", AppletConstant.APP_ID);
		params.put("qualNum", "");
		params.put("qualType", "");
		params.put("qualValue", "");
		params.put("count", "");

		//流水号（确保唯一）
		String transNumber = Utils.createNonceNumber();
		params.put("transNumber", transNumber);

		//资格起始时间 格式为yyyyMMdd
		String startDate = Utils.getCurrentDateTime("yyyyMMdd");
		params.put("startDate", startDate);

		//资格结束时间 格式为yyyyMMdd
		String date = Utils.getCurrentDateTime("yyyyMMdd");
		String endDate = Utils.dateToString(Utils.addDay(Utils.stringToDate(date),30),"yyyyMMdd");
		params.put("endDate", endDate);

		//生成随即字符串
		String nonceStr = Utils.createNonceStr();
		params.put("nonceStr", nonceStr);

		//生成时间戳
		String timestamp = String.valueOf(System.currentTimeMillis()/1000);
		params.put("timestamp", timestamp);

		//签名
		String signature = Utils.sign(params, AppletConstant.SIGN_KEY_PACKET);
		params.put("signature", signature);

		//针对敏感字段加密
		Utils.encryptedParamMap(AppletConstant.SYMMETRIC_KEY, params, "qualValue", "count");
		//发送请求
		String resultStr = Utils.sendPostGson(url, params);
		
		System.out.println("-------抽奖资格赠送:"+resultStr+"---------");
	}
	
}
